using System;
using Autofac;

namespace EventBus
{
    /// <summary>
    /// 事件总线模块入口
    /// </summary>
    public class EventBusModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.Register(c => new EventBusImpl(c.Resolve<Func<Broadcast>>()))
                .As<IEventBus>()
                .As<IEventListenerAction>()
                .As<IEventBroadcast>()
                .As<IEventListenerFunc>()
                .As<IEventBroadcastAndReturn>()
                .As<IEventListenerActionAsync>()
                .As<IEventBroadcastAsync>()
                .As<IEventListenerFuncAsync>()
                .As<IEventBroadcastAndReturnAsync>()
                .SingleInstance();

            builder.Register(c => new Broadcast(c.Resolve<Sender>()))
                .AsSelf()
                .As<IBroadcast>();
            
            builder.Register(c => new Sender())
                .AsSelf()
                .As<ISender>()
                .SingleInstance();
        }
    }
}